package com.wangy.service.impl;

import com.wangy.bean.User;
import com.wangy.bean.UserLoginInfo;
import com.wangy.service.IndexService;
import com.wangy.service.PermissionService;
import com.wangy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * *@Author yyzb
 * *@Date 2024/12/27 13:32
 * *@Version 1.0
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    UserService userService;

    @Autowired
    PermissionService permissionService;

    @Override
    public UserLoginInfo getUserInfo(String userName) {
        User user = userService.getUserByName(userName);

        // 根据用户id获得权限列表
        if (user != null) {
            List<String> permissionByUserId = permissionService.getPermissionByUserId(user.getId());
            UserLoginInfo userLoginInfo = new UserLoginInfo();
            userLoginInfo.setUsername(user.getUsername());
            userLoginInfo.getRoutes().addAll(permissionByUserId);
            return userLoginInfo;
        }
        return null;
    }
}
